package cn.yilongquan.service.impl;

import cn.yilongquan.mapper.PermissionMapper;
import cn.yilongquan.service.IPermissionService;
import cn.yilongquan.system.domain.Permission;
import cn.yilongquan.system.query.PermissionQuery;
import cn.yilongquan.util.R;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PermissionServiceImpl implements IPermissionService {
    @Autowired
    private PermissionMapper permissionMapper;

    @Override
    public Permission findById(Long id) {
        return permissionMapper.findById(id);
    }

    @Override
    public List<Permission> findAll() {
        return permissionMapper.findAll();
    }

    @Override
    public void add(Permission permission) {
        permissionMapper.add(permission);
    }

    @Override
    public void update(Permission permission) {
        permissionMapper.update(permission);
    }

    @Override
    public void deleteById(Long id) {
        permissionMapper.deleteById(id);
    }

    @Override
    public void batchDelete(List<Long> ids) {
        permissionMapper.batchDelete(ids);
    }

    @Override
    public R pageList(PermissionQuery permissionQuery) {
        //自动分页
        PageHelper.startPage(permissionQuery.getPage(), permissionQuery.getSize());
        List<Permission> permissions = permissionMapper.pageList(permissionQuery);
        return R.ok(new PageInfo<Permission>(permissions));
    }
}